//
//  ONEChatMsgCell.m
//  ONEChat
//
//  Created by 楼楚 on 16/5/26.
//  Copyright © 2016年 Chu Lou. All rights reserved.
//

#import "ONEChatMsgCell.h"

@implementation ONEChatMsgCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self buildCell];
    }
    return self;
}
- (void)buildCell{
//    设置聊天气泡
    UIImage *leftImage = [UIImage imageNamed:@"ReceiverTextNodeBkg.png"];
    UIImage *rightImage = [UIImage imageNamed:@"SenderTextNodeBkg.png"];
//    生成新image
    leftImage = [leftImage stretchableImageWithLeftCapWidth:30 topCapHeight:35];
    rightImage = [rightImage stretchableImageWithLeftCapWidth:30 topCapHeight:35];
//    发送方
    self.rightChatView = [[UIImageView alloc]init];
    self.rightChatView.image = rightImage;
    [self.contentView addSubview:self.rightChatView];
    
    self.rightTextLabel = [[UILabel alloc]init];
    self.rightTextLabel.font = [UIFont systemFontOfSize:14.f];
    self.rightTextLabel.backgroundColor = [UIColor clearColor];
    self.rightTextLabel.numberOfLines = 0;
    [self.rightChatView addSubview:self.rightTextLabel];//文本消息label放在泡泡内
    
    self.rightAvatarView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"me.png"]];
    self.rightAvatarView.layer.masksToBounds = YES;
    self.rightAvatarView.layer.cornerRadius = 12.f;
    [self.contentView addSubview:self.rightAvatarView];
    
    self.rightImgView = [[UIImageView alloc]init];
    self.rightImgView.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:self.rightImgView];
    
    self.rightVideoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:self.rightVideoBtn];
    
//    接收方
    self.leftChatView = [[UIImageView alloc]init];
    self.leftChatView.image = leftImage;
    [self.contentView addSubview:self.leftChatView];
    
    self.leftTextLabel = [[UILabel alloc]init];
    self.leftTextLabel.font = [UIFont systemFontOfSize:14.f];
    self.leftTextLabel.backgroundColor = [UIColor clearColor];
    self.leftTextLabel.numberOfLines = 0;
    [self.leftChatView addSubview:self.leftTextLabel];//文本消息label放在泡泡内
    
    self.leftAvatarView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"you.png"]];
    self.leftAvatarView.layer.masksToBounds = YES;
    self.leftAvatarView.layer.cornerRadius = 12.f;
    [self.contentView addSubview:self.leftAvatarView];
    
    self.leftImgView = [[UIImageView alloc]init];
    self.leftImgView.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:self.leftImgView];
    
    self.leftVideoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:self.leftVideoBtn];
    
//    添加时间label
    self.timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, 5)];
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"MM-dd hh:mm:ss"];
    self.timeLabel.text = [formatter stringFromDate:[NSDate date]];
    self.timeLabel.font = [UIFont systemFontOfSize:5.f];
    self.timeLabel.textColor = [UIColor blackColor];
    self.timeLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.timeLabel];
    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
